import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
let devServer = {
  host:"localhost",
  port:5173,
  proxyTarget:"http://localhost:8080"
}
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server:{
    host: devServer.host,
    port: devServer.port,
    proxy: {
      "/api": {
        target: devServer.proxyTarget,
        changeOrigin: true,
        rewrite: path => {
          let rewritePath = path;
          console.log(`>> http proxy: 'http://${devServer.host}:${devServer.port}${path}' -> '${devServer.proxyTarget}${rewritePath}'`);
          return rewritePath;
        }
      }
    }
  }
})
